var prefix = ctx + "/warn/warnings"
$().ready(function() {
	initTemplateDownLoad();
	validateRule();
});

function doCheck() {
	var ok = true;
	var fileDir = $("#excelFile").val();     
	var suffix = fileDir.substr(fileDir.lastIndexOf("."));     
	if ("" == fileDir) {
		layer.alert("请选择需要导入的Excel文件！");
		ok = flase;     
	}     
	if (".xls" != suffix && ".xlsx" != suffix) {
		layer.alert("请选择Excel格式的文件导入！");
		$('#file').val("");
		ok = false;    
	}  
	if (ok) {
		var form = $('#signupForm')[0];

		// Create an FormData object
		var data = new FormData(form);

		$.ajax({
			type: "POST",
			enctype: 'multipart/form-data',
			url: "/warn/warnings/doCheck",
			data: data,
			processData: false,
			contentType: false,
			async: false,
			error: function(request) {
				alert("Connection error");
			},
			success: function(row) {
				var html = "成功条数：" + row.successCount + "</br>";
				html += "重复条数：" + row.duplicateCount + "</br>";
				html += "失败条数：" + row.errorCount;

				setTimeout(function() {
					parent.layer.msg(html);
					parent.reLoad();
				}, 2000);
			}
		});
	}
}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			
		},
		messages : {
			
		},
	})
}

function initTemplateDownLoad() {
	//var inspectType = $('#inspectType').val();
	var inspectType = 1;
	if(inspectType == 1){
		$('#downTemplate').html('<a href="/upload/inspectTemplate/企业模板.xlsx">企业模板</a>');
	}else if(inspectType == 2){
		$('#downTemplate').html('<a href="/upload/inspectTemplate/自然人模板.xlsx">自然人模板</a>');
	}
}



